// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Text, View, Image, TouchableOpacity, ImageBackground, TextInput, ScrollView, InteractionManager } from 'react-native';

// 引入第三方依赖
import _ from 'lodash';
import pureRender from 'pure-render-decorator';
import { Actions } from 'react-native-router-flux';
import Icon from 'react-native-vector-icons/Ionicons';

// antd 按需加载
import { Tabs, Toast, Portal } from '@ant-design/react-native';

// 引入 处理数据 所需文件
import { updatePassword } from '../../module/module.js'

// 引入样式
import Style from './style/style.js';

// 引入公用组件
import { Status, NavBar, CacheImage, Layout } from '../../components/index.js'

// 引入专用组件
import { } from './components'

// 引入工具包
import { } from '../../util/images.js';
import { press, size, ScreenWidth, defaultDataList, onEndReached, onRefresh, concatDataList, defaultPage } from '../../util/utils.js'

class ChangePassword extends Component {

  constructor(props) {
    super(props)
    this.state = {

    }
  }


  componentDidMount() {

  }


  updatePassword() {
    const { currentPwd, password } = this;
    if (!currentPwd._lastNativeText) {
      Toast.info('请输入验证码', 1);
      return;
    }
    if (!password._lastNativeText) {
      Toast.info('请输入验证码', 1);
      return;
    }
    this.loading = Toast.loading('登录中', 0);
    updatePassword({
      currentPwd: currentPwd._lastNativeText,
      password: password._lastNativeText,
    }).then((res) => {
      Actions.pop()
      console.log(res)
      Toast.success(res.message)
    }).catch((error) => {
      Toast.info(error.message, 1);
    }).finally(() => {
      Portal.remove(this.loading)
    })

  }

  render() {
    return (
      <Layout
        style={{ backgroundColor: '#fff' }}
        header={<Status />}
      >
        <NavBar
          title="修改密码"
          back={true}
        />
        <ScrollView style={Style.content}>
          <View style={{
            paddingHorizontal: 40,
            paddingVertical: 30,
            backgroundColor: '#fff'
          }}
          >
            <View style={{
              flexDirection: 'row',
              alignItems: 'center',
              borderBottomWidth: 1,
              borderBottomColor: '#ccc',
              marginBottom: 20
            }}
            >
              {/* C3DF7C */}
              <TextInput
                ref={(r) => this.currentPwd = r}
                placeholder="请输入当前密码"
                placeholderTextColor="#ccc"
                style={{
                  flex: 1,
                  fontSize: 14,
                  paddingVertical: 14,
                  borderWidth: 0,
                  paddingHorizontal: 5,
                  color: '#000',
                }}
                underlineColorAndroid="transparent"
              />
            </View>
            <View style={{
              flexDirection: 'row',
              alignItems: 'center',
              borderBottomWidth: 1,
              borderBottomColor: '#ccc',
              marginBottom: 20
            }}
            >
              <TextInput
                ref={(r) => this.password = r}
                placeholder="请输入新密码"
                placeholderTextColor="#ccc"
                style={{
                  flex: 1,
                  fontSize: 14,
                  paddingVertical: 14,
                  borderWidth: 0,
                  paddingHorizontal: 5,
                  color: '#000',
                }}
                underlineColorAndroid="transparent"
              />
            </View>
            <TouchableOpacity
              activeOpacity={0.9}
              onPress={() => this.updatePassword()}
              style={{
                marginTop: 15,
                paddingVertical: 14,
                paddingHorizontal: 20,
                backgroundColor: '#000',
                borderRadius: 0,
                alignItems: 'center',
                justifyContent: 'center',
                marginBottom: 15,
              }}
            >
              <Text style={{ fontSize: size(28), color: '#fff', lineHeight: size(30), }}>提交</Text>
            </TouchableOpacity>
          </View>
        </ScrollView>
      </Layout >
    );
  }
}


export default connect(({ user }) => ({
  user,
}))(pureRender(ChangePassword))
